//
//  DBYSubjectTableViewCell.m
//  MemoryTravel
//
//  Created by dllo on 15/12/28.
//  Copyright © 2015年 fcx. All rights reserved.
//

#import "DBYSubjectTableViewCell.h"

@implementation DBYSubjectTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}

-(void)createSubViews{
    
    self.backImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10 , 5 , Width - 10 * 2 , 220 )];
    [self.contentView addSubview:self.backImageView];
    self.backImageView.userInteractionEnabled = YES;
    
    self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.backImageView.frame.origin.x + 5 , self.backImageView.frame.size.height - 30  - 20 , Width, 30)];
    [self.contentView addSubview:self.nameLabel];
    self.nameLabel.textColor = [UIColor whiteColor];
    self.nameLabel.font = [UIFont boldSystemFontOfSize:20];
    self.nameLabel.numberOfLines = 0;
    
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.backImageView.frame.origin.x + 5 , self.backImageView.frame.size.height - 20 , Width, 20 )];
    [self.contentView addSubview:self.titleLabel];
    self.titleLabel.textColor = [UIColor whiteColor];
    self.titleLabel.font = [UIFont systemFontOfSize:13];

//    NSLog(@"++");
////    self.backImageView = [[UIImageView alloc] init];
////    self.backImageView.frame = CGRectMake(0, 0, 100, 100);
////    self.backgroundView.backgroundColor = [UIColor redColor];
////    [self.contentView addSubview:self.backImageView];
//    
////    
////    [self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
////       
////        make.left.equalTo(self.mas_left);
////        make.top.equalTo(self.mas_top);
////        make.size.mas_equalTo(CGSizeMake(Width - 20, 220));
////        
////    }];
//    self.backImageView.userInteractionEnabled = YES;
//    
//    self.nameLabel = [[UILabel alloc] init];
//    [self.contentView addSubview:self.nameLabel];
////    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
////       
////        make.left.equalTo(self.backImageView.mas_left).offset(5);
////        make.top.equalTo(self.backImageView.mas_bottom).offset(50);
////        make.size.mas_equalTo(CGSizeMake(Width, 30));
////    }];
//    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        
//        make.left.mas_equalTo(5);
//        make.top.mas_equalTo(10);
//        make.size.mas_equalTo(CGSizeMake(Width, 30));
//    }];
//
//    self.nameLabel.textColor = [UIColor whiteColor];
//    self.nameLabel.font = [UIFont boldSystemFontOfSize:20];
//    self.nameLabel.numberOfLines = 0;
////
////    self.titleLabel = [[UILabel alloc] init];
////    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
////       
////        make.left.equalTo(self.backImageView.mas_left).offset(5);
////        make.top.equalTo(self.backImageView.mas_bottom).offset(-20);
////        make.size.mas_equalTo(CGSizeMake(Width, 20));
////    }];
////    [self.contentView addSubview:self.titleLabel];
////    self.titleLabel.textColor = [UIColor whiteColor];
////    self.titleLabel.font = [UIFont systemFontOfSize:13];
    
}

-(void)setAModel:(DBYSubjectModel *)aModel
{
    
    if (_aModel != aModel) {
        
        _aModel = aModel;
    }
    
    self.nameLabel.text = self.aModel.name;
    self.titleLabel.text = self.aModel.title;
    self.backImageView.contentMode = UIViewContentModeScaleAspectFill;
    self.backImageView.clipsToBounds = YES;
    [self.backImageView sd_setImageWithURL:[NSURL URLWithString:self.aModel.image_url] placeholderImage:[UIImage imageNamed:@"loading.jpg"]];

    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
